<?php
/**
 * 反馈接口
 * 获取专家信息,专家认证
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\ApiController;

class FeedBackController extends ApiController
{
    public function rest()
    {
        switch ($this->_method) {
            case 'post': // post请求处理代码
                $this->_post();
                break;
        }
    }

    /**
     * 添加反馈信息,如果成功则给该用户添加积分
     */
    private function _post()
    {
        if (!$this->addFeedBack(I('post.'))) {
            $this->myApiPrint(C('STATUS')['228'], 201);
        } else {
            D('MemberProfile')->add_score($this->userId, 'sa_feedback');
            $this->myApiPrint(C('STATUS')['229'], 200);
        }
    }

    /**
     * 添加反馈信息
     * @param $info
     * @return bool
     */
    public function addFeedBack($info)
    {
        $feed_back = M('feed_back');
        $data['uid'] = $this->userId;
        $data['feed_content'] = $info['feed_content'];
        $data['feed_mail'] = $info['feed_mail'];
        $data['addtime'] = time();
        $request = $feed_back->add($data);
        return $request ? true : false;
    }
}
